From e98b9dbec8342a552c93ca23332d949880d1ecc7 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 16 Oct 2017 16:05:47 -0400 Subject: [PATCH] Add more tests about documenting lib vs bins with the same name --- tests/doc.rs | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/tests/doc.rs b/tests/doc.rs index c61428bef..32379c37b 100644 --- a/tests/doc.rs +++ b/tests/doc.rs @@ -369,7 +369,7 @@ fn doc_lib_bin_same_name_documents_lib() { assert_that(p.cargo("doc"), execs().with_status(0).with_stderr(&format!("\ -[..] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", dir = path2url(p.root())))); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -381,6 +381,116 @@ fn doc_lib_bin_same_name_documents_lib() { assert!(!doc_html.contains("Binary")); } +#[test] +fn doc_lib_bin_same_name_documents_lib_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--lib"), + execs().with_status(0).with_stderr(&format!("\ +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(doc_html.contains("Library")); + assert!(!doc_html.contains("Binary")); +} + +#[test] +fn doc_lib_bin_same_name_documents_named_bin_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--bin").arg("foo"), + execs().with_status(0).with_stderr(&format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(!doc_html.contains("Library")); + assert!(doc_html.contains("Binary")); +} + +#[test] +fn doc_lib_bin_same_name_documents_bins_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--bins"), + execs().with_status(0).with_stderr(&format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(!doc_html.contains("Library")); + assert!(doc_html.contains("Binary")); +} + #[test] fn doc_dash_p() { let p = project("foo") -- 2.30.2